package com.uphone.kingmall.activity.order;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.china.zhuoyue.R;
import com.flyco.tablayout.SlidingTabLayout;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.base.BaseFragment;
import com.uphone.kingmall.fragment.order.WaitEvaluateFragment;
import com.uphone.kingmall.fragment.order.WaitPayFragment;
import com.uphone.kingmall.fragment.order.WaitShareFragment;
import com.uphone.kingmall.fragment.order.WaitShipmentsFragment;
import com.uphone.kingmall.fragment.order.WaitTakeGoodsFragment;
import com.uphone.kingmall.utils.intent.IntentData;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 孙增艳
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2019/2/25
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class AllOrderActivity extends BaseActivity {
    @BindView(R.id.stl_order)
    SlidingTabLayout stlOrder;
    @BindView(R.id.vp_order)
    ViewPager vpOrder;
    @IntentData
    private int type = 0;

    private String[] titles = new String[]{"待分享", "待付款", "待发货", "待收货", "待评价"};
    //	空所有订单;0已取消；10待付款；20待发货；30待收货；40待评价；50已完成；60售后
    private BaseFragment[] fragments = new BaseFragment[]{WaitShareFragment.newInstance(), WaitPayFragment.newInstance(),
            WaitShipmentsFragment.newInstance(), WaitTakeGoodsFragment.newInstance(), WaitEvaluateFragment.newInstance()};

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_all_order;
    }

    @Override
    public void initView() {
        setStatusBar();
        MyFragmentPageAdapter fragmentPageAdapter = new MyFragmentPageAdapter(getSupportFragmentManager());
        vpOrder.setAdapter(fragmentPageAdapter);
        stlOrder.setViewPager(vpOrder, titles);
        setCurrentItem(type);
    }

    public void setCurrentItem(int type) {
        vpOrder.setCurrentItem(type);
    }

    @Override
    public void loadJPush() {
        super.loadJPush();
        for (int i = 0; i < fragments.length; i++) {
            if (fragments[i] != null) {
                if (fragments[i] instanceof WaitShareFragment) {
                    ((WaitShareFragment) fragments[i]).loadJPush();
                } else if (fragments[i] instanceof WaitPayFragment) {
                    ((WaitPayFragment) fragments[i]).loadJPush();
                } else if (fragments[i] instanceof WaitShipmentsFragment) {
                    ((WaitShipmentsFragment) fragments[i]).loadJPush();
                } else if (fragments[i] instanceof WaitTakeGoodsFragment) {
                    ((WaitTakeGoodsFragment) fragments[i]).loadJPush();
                } else if (fragments[i] instanceof WaitEvaluateFragment) {
                    ((WaitEvaluateFragment) fragments[i]).loadJPush();
                }
            }
        }
    }

    @Override
    public void initData() {

    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    public class MyFragmentPageAdapter extends FragmentPagerAdapter {

        public MyFragmentPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragments[i];
        }

        @Override
        public int getCount() {
            return fragments.length;
        }

    }
}
